import createPersistedState from 'vuex-persistedstate';
import storageAdapter from './storage-adapter';

// 自定义存储引擎
const customStorage = {
	getItem: (key) => {
		return storageAdapter.getItem(key)
	},
	setItem: (key, value) => {
		storageAdapter.setItem(key, value)
	},
	removeItem: (key) => {
		storageAdapter.removeItem(key)
	},
	clear: () => {
		storageAdapter.clear()
	}
};

// 创建持久化插件
export default function createCustomPersistedState(options = {}) {
	return createPersistedState({
		key: 'vuex', // 存储的key名
		storage: customStorage, // 自定义存储
		paths: [], // 需要持久化的state路径，空数组表示全部持久化
		...options
	});
}